package com.gotop.common.node;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: cem
 * @description:
 * @author: superfish
 * @create: 2020-12-22 10:57
 **/
public class BaseNode implements INode {
    private static final long serialVersionUID = 1L;
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    protected Long id;
    @JsonSerialize(
            using = ToStringSerializer.class
    )
    protected Long parentId;
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    protected List<INode> children = new ArrayList();
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private Boolean hasChildren;

    public Boolean getHasChildren() {
        if (null == this.hasChildren) {
            return false;
        }
        return this.children.size() > 0 ? true : this.hasChildren;
    }

    public BaseNode() {
    }

    public Long getId() {
        return this.id;
    }

    public Long getParentId() {
        return this.parentId;
    }

    public List<INode> getChildren() {
        return this.children;
    }

    public void setId(final Long id) {
        this.id = id;
    }

    public void setParentId(final Long parentId) {
        this.parentId = parentId;
    }

    public void setChildren(final List<INode> children) {
        this.children = children;
    }

    public void setHasChildren(final Boolean hasChildren) {
        this.hasChildren = hasChildren;
    }
}